package com.lfnyxy.service.imp;

import com.lfnyxy.dao.ProviceRefDao;
import com.lfnyxy.dto.DropVo;
import com.lfnyxy.entity.ProviceRefEntity;
import com.lfnyxy.query.ProviceRefQuery;
import com.lfnyxy.service.ProviceRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProviceRefServiceImp implements ProviceRefService {
    @Autowired
    public ProviceRefDao proviceRefDao;

    public int CreateItem(ProviceRefEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return proviceRefDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(ProviceRefEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return proviceRefDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <ProviceRefEntity> QueryPageList(ProviceRefQuery query) {
        int count = proviceRefDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return proviceRefDao.QueryPageList(query);
        }
        return null;
    }

    public List <ProviceRefEntity> QueryAll() {
        return proviceRefDao.QueryAll();
    }

    public ProviceRefEntity QueryItem(int Id) {
        if (Id > 0) {
            return proviceRefDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return proviceRefDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    @Override
    public List <DropVo> QueryDrop() {
        return proviceRefDao.QueryDrop();
    }

    private boolean CheckIsExist(ProviceRefEntity entity) {
        if (entity != null) {
            return proviceRefDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}